home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / x / volume6 / vine / patch1 < prev    next >
Encoding:
Internet Message Format  |  1990-03-15  |  15.9 KB

  1. Path: uunet!wyse!mips!apple!sun-barr!newstop!sun!sun.com!argv
  2. From: argv@sun.com
  3. Newsgroups: comp.sources.x
  4. Subject: v06i032: vine, Patch1
  5. Message-ID: <132964@sun.Eng.Sun.COM>
  6. Date: 15 Mar 90 07:44:17 GMT
  7. Sender: news@sun.Eng.Sun.COM
  8. Lines: 592
  9. Approved: argv@sun.com
  10.  
  11. Submitted-by: argv@sun.com
  12. Posting-number: Volume 6, Issue 32
  13. Archive-name: vine/patch1
  14. Patch-To: vine: Volume 6, Issue 25
  15.  
  16. The following patch to vine fixes the problem
  17. with forking.  so, some of the more interesting
  18. parameters now workd:
  19.     vine -C -c
  20.     vince -CfDc
  21. Due to a bug with xnews, you're going to have a problem
  22. allocating colors correctly.  It's been reported already.
  23.  
  24. *** Imakefile.orig    Sat Mar 10 12:41:04 1990
  25. --- Imakefile    Wed Mar 14 11:19:36 1990
  26. ***************
  27. *** 2,8 ****
  28.   #include BandAidCompiler
  29.   #endif
  30.   
  31. ! DEFINES -DX11
  32.   INCLUDES = -I$(TOP) -I$(TOP)/X11
  33.   SYS_LIBRARIES = -lm
  34.   LOCAL_LIBRARIES = $(XLIB)
  35. --- 2,8 ----
  36.   #include BandAidCompiler
  37.   #endif
  38.   
  39. ! DEFINES = -DX11
  40.   INCLUDES = -I$(TOP) -I$(TOP)/X11
  41.   SYS_LIBRARIES = -lm
  42.   LOCAL_LIBRARIES = $(XLIB)
  43. *** version.h.orig    Wed Mar 14 23:02:20 1990
  44. --- version.h    Wed Mar 14 23:02:33 1990
  45. ***************
  46. *** 1,2 ****
  47. ! #define PATCHLEVEL 0
  48. ! #define PATCHDATE  3/9/90
  49. --- 1,2 ----
  50. ! #define PATCHLEVEL 1
  51. ! #define PATCHDATE  3/14/90
  52. *** vine.c.orig    Fri Mar  9 18:44:25 1990
  53. --- vine.c    Wed Mar 14 22:23:11 1990
  54. ***************
  55. *** 5,10 ****
  56. --- 5,13 ----
  57.    *
  58.    *  compile: cc -O -s vine.c -lsunwindow -lpixrect -lm -o vine
  59.    *
  60. +  *  Updating to work on X11 March 1990.
  61. +  *  compile: cc -O -s vine.c -DX11 -lX11 -lm -o vine
  62. +  *
  63.    * The way vines works is a "stem" grows and leaves grow from that stem.
  64.    * The stem and the leaf are arrays of "points" (struct pr_pos).  You can
  65.    * add your own images (like flowers or something) with the -S and -L
  66. ***************
  67. *** 49,55 ****
  68.       "-R N: have N different leaf rotations (max 360)",
  69.   #ifdef X11
  70.       "-d display: use display:server[.screen]",
  71. -     "-F: allow forking; off by default because X server gets confused",
  72.   #else /* X11 */
  73.       "-d device: use alternate frame buffer; default is /dev/fb",
  74.       "-w:  vines grow around each window on the screen (not icons; no color)",
  75. --- 52,57 ----
  76. ***************
  77. *** 73,85 ****
  78.   #include <X11/Xatom.h>
  79.   #include <X11/Xlib.h>
  80.   #include <X11/Xutil.h>
  81. ! struct pr_pos {
  82. !     short x, y;
  83. ! };
  84.   struct rect {
  85.       int    r_left, r_top, r_width, r_height;
  86.   };
  87.   #else /* X11 */
  88.   #include <suntool/tool_hs.h>
  89.   #include <pixrect/pixrect_hs.h>
  90.   #include <suntool/wmgr.h>
  91. --- 75,86 ----
  92.   #include <X11/Xatom.h>
  93.   #include <X11/Xlib.h>
  94.   #include <X11/Xutil.h>
  95. ! typedef XPoint point_t;
  96.   struct rect {
  97.       int    r_left, r_top, r_width, r_height;
  98.   };
  99.   #else /* X11 */
  100. + typedef struct pr_pos point_t;
  101.   #include <suntool/tool_hs.h>
  102.   #include <pixrect/pixrect_hs.h>
  103.   #include <suntool/wmgr.h>
  104. ***************
  105. *** 88,93 ****
  106. --- 89,95 ----
  107.   #define WidthOfScreen(s) s->pr_size.x
  108.   #define HeightOfScreen(s) s->pr_size.y
  109.   #define WUF_WMGR1 0x10
  110. + #define XFlush(dpy) /* not used in Suntools */
  111.   #endif /* X11 */
  112.   
  113.   #include <sys/wait.h>
  114. ***************
  115. *** 118,124 ****
  116.   /*
  117.    * each {x,y} is a relative point to 0,0. End is {0,0} pair
  118.    */
  119. ! struct pr_pos leaf[] = {
  120.       {-4,4}, {-9,6}, {-13,9}, {-15,11}, {-16,14}, {-17,16}, {-17,20},
  121.       {-16,24}, {-13,28}, {-11,30}, {-9,32}, {-4,36}, {-1,38}, {4,39}, {6,37},
  122.       {4,37}, {3,34}, {3,31}, {4,29}, {6,25}, {9,20}, {10,16}, {10,12},
  123. --- 120,126 ----
  124.   /*
  125.    * each {x,y} is a relative point to 0,0. End is {0,0} pair
  126.    */
  127. ! point_t leaf[] = {
  128.       {-4,4}, {-9,6}, {-13,9}, {-15,11}, {-16,14}, {-17,16}, {-17,20},
  129.       {-16,24}, {-13,28}, {-11,30}, {-9,32}, {-4,36}, {-1,38}, {4,39}, {6,37},
  130.       {4,37}, {3,34}, {3,31}, {4,29}, {6,25}, {9,20}, {10,16}, {10,12},
  131. ***************
  132. *** 125,139 ****
  133.       {8,8}, {7,7}, {4,6}, {2,4}, {1,0}, {0,2}, {-1,4}, {-3,8},
  134.       {-5,12}, {-6,16}, {-6,20}, {-5,24}, {-3,27}, {0,0}
  135.   };
  136. ! int leafsize = sizeof (leaf) / sizeof (struct pr_pos);
  137.   
  138. ! struct pr_pos stem[50] = {
  139.       {0,7}, {1,8}, {2,7}, {1,12}, {0,11}, {-1,12}, {-3,15}, {-3,19}, {-2,22},
  140.       {-1,24}, {1,26}, {3,28}, {4,30}, {5,32}, {5,36}, {7,40}, {8,42}, {9,43},
  141.       {8,49}, {5,51}, {2,54}, {0,60}, {0,0}
  142.   };
  143. ! int stemsize = sizeof (stem) / sizeof (struct pr_pos);
  144. ! struct pr_pos leaves[360][sizeof(leaf) / sizeof(struct pr_pos)];
  145.   struct rect win_rects[32];
  146.   
  147.   int reverse;          /*  -r:  reverse video */
  148. --- 127,141 ----
  149.       {8,8}, {7,7}, {4,6}, {2,4}, {1,0}, {0,2}, {-1,4}, {-3,8},
  150.       {-5,12}, {-6,16}, {-6,20}, {-5,24}, {-3,27}, {0,0}
  151.   };
  152. ! int leafsize = sizeof (leaf) / sizeof (point_t);
  153.   
  154. ! point_t stem[50] = {
  155.       {0,7}, {1,8}, {2,7}, {1,12}, {0,11}, {-1,12}, {-3,15}, {-3,19}, {-2,22},
  156.       {-1,24}, {1,26}, {3,28}, {4,30}, {5,32}, {5,36}, {7,40}, {8,42}, {9,43},
  157.       {8,49}, {5,51}, {2,54}, {0,60}, {0,0}
  158.   };
  159. ! int stemsize = sizeof (stem) / sizeof (point_t);
  160. ! point_t leaves[360][sizeof(leaf) / sizeof(point_t)];
  161.   struct rect win_rects[32];
  162.   
  163.   int reverse;          /*  -r:  reverse video */
  164. ***************
  165. *** 150,163 ****
  166.   int do_edges;          /*  -e:  just traverse the edges of the screen */
  167.   int do_windows;       /*  -w:  grow around each open window in suntools */
  168.   int season;          /*  -f:  fall season */
  169. - int do_fork;          /*  -F:  allow forking -- off for X */
  170.   int fade;          /*  -D:  fade the color down the colormap */
  171.   
  172. ! unsigned long colors[256];
  173.   int max_color;        /* maximum number of colors available */
  174.   int win_no, my_win;   /* number of windows running / which win we are */
  175.   int total_forks;      /* the total number of forks we've done so far */
  176.   
  177.   #ifdef X11
  178.   unsigned long intensity;        /* shade of color to paint */
  179.   Display *dpy; /* display */
  180. --- 152,166 ----
  181.   int do_edges;          /*  -e:  just traverse the edges of the screen */
  182.   int do_windows;       /*  -w:  grow around each open window in suntools */
  183.   int season;          /*  -f:  fall season */
  184.   int fade;          /*  -D:  fade the color down the colormap */
  185.   
  186. ! unsigned long colors[255];
  187.   int max_color;        /* maximum number of colors available */
  188.   int win_no, my_win;   /* number of windows running / which win we are */
  189.   int total_forks;      /* the total number of forks we've done so far */
  190.   
  191. + char *prog_name;
  192.   #ifdef X11
  193.   unsigned long intensity;        /* shade of color to paint */
  194.   Display *dpy; /* display */
  195. ***************
  196. *** 185,190 ****
  197. --- 188,195 ----
  198.       int c;
  199.       int dead_kids();
  200.   
  201. +     prog_name = argv[0];
  202.       if (argc > 1)
  203.       parse_args(argc, argv);
  204.       else
  205. ***************
  206. *** 227,265 ****
  207.       }
  208.       }
  209.   
  210. - #ifdef X11
  211. - {
  212. -     void x_error();
  213. -     char *getenv(), *p = getenv("DISPLAY");
  214. -     if (!(dpy = XOpenDisplay(device? device : p? p : ""))) {
  215. -     fprintf(stderr, "%s: unable to open display '%s'\n",
  216. -         argv[0], XDisplayName(p));
  217. -     exit(1);
  218. -     }
  219. -     /* XSynchronize(dpy, 1); */
  220. -     XSetErrorHandler(x_error);
  221. -     screen = ScreenOfDisplay(dpy, DefaultScreen(dpy));
  222. -     win = RootWindowOfScreen(screen);
  223. -     gc = XCreateGC(dpy, win, 0L, NULL);
  224. - }
  225. - #else /* X11 */
  226. - {
  227. -     char groups[PIXPG_OVERLAY+1];
  228. -     if (!(screen = pr_open(device)))
  229. -     exit(1); /* pr_open prints its own error messages (bad idea) */
  230. -     pr_available_plane_groups(screen, sizeof(groups), groups);
  231. -     if (groups[PIXPG_OVERLAY] && groups[PIXPG_OVERLAY_ENABLE] && !is_color) {
  232. -     pr_set_plane_group(screen, PIXPG_OVERLAY_ENABLE);
  233. -     pr_rop(screen, 0,0, WidthOfScreen(screen), HeightOfScreen(screen),
  234. -         PIX_SET, (Pixrect *) 0,0,0);
  235. -     pr_set_plane_group(screen, PIXPG_OVERLAY);
  236. -     }
  237. -     do_fork++;
  238. - }
  239. - #endif /* X11 */
  240.       if (do_halt || from_center)
  241.       /* don't count this fork ... */
  242.       if (fork())
  243. --- 232,237 ----
  244. ***************
  245. *** 274,282 ****
  246.           putchar('.');
  247.       }
  248.       puts(" done.");
  249. !     if (is_color)
  250. !     initialize_color();
  251. !     else if (do_windows) {
  252.       if (!get_windows())
  253.           puts("No windows!");
  254.   
  255. --- 246,254 ----
  256.           putchar('.');
  257.       }
  258.       puts(" done.");
  259. !     init_display();
  260. ! #ifndef X11
  261. !     if (!is_color && do_windows) {
  262.       if (!get_windows())
  263.           puts("No windows!");
  264.   
  265. ***************
  266. *** 291,306 ****
  267.                   win_rects[my_win].r_top, FLOP);
  268.       exit(0);
  269.       }
  270.       y = 1;
  271.       if (do_edges) {
  272. !     if (do_fork) {
  273. !         if (!fork()) {
  274. !         edge_vines(WidthOfScreen(screen) / 2, 10, FLIP);
  275. !         exit(0);
  276. !         }
  277. !     } else
  278.           edge_vines(WidthOfScreen(screen) / 2, 10, FLIP);
  279. !     edge_vines(WidthOfScreen(screen) / 2, 10, FLOP);
  280.       exit(0);
  281.       }
  282.   #ifdef SIGCHLD
  283. --- 263,276 ----
  284.                   win_rects[my_win].r_top, FLOP);
  285.       exit(0);
  286.       }
  287. + #endif /* X11 */
  288.       y = 1;
  289.       if (do_edges) {
  290. !     if (!fork()) {
  291. !         init_display();
  292.           edge_vines(WidthOfScreen(screen) / 2, 10, FLIP);
  293. !     } else
  294. !         edge_vines(WidthOfScreen(screen) / 2, 10, FLOP);
  295.       exit(0);
  296.       }
  297.   #ifdef SIGCHLD
  298. ***************
  299. *** 312,320 ****
  300.           random_vines(WidthOfScreen(screen)/2, HeightOfScreen(screen)/2);
  301.       else
  302.           random_vines(x, y);
  303. - #ifdef X11
  304. -     XFlush(dpy);
  305. - #endif /* X11 */
  306.   }
  307.   
  308.   #ifdef SIGCHLD
  309. --- 282,287 ----
  310. ***************
  311. *** 357,362 ****
  312. --- 324,330 ----
  313.       draw_stem(&x, &y,
  314.           (random() % 2) * UP | ((which_way == FLIP) ? FLOP : FLIP));
  315.       */
  316. +     XFlush(dpy);
  317.   }
  318.   
  319.   random_vines(xstart, ystart)
  320. ***************
  321. *** 366,371 ****
  322. --- 334,340 ----
  323.       total_forks++;
  324.       return;
  325.       }
  326. +     init_display();
  327.       /* make the child think there are too many forks */
  328.       total_forks = MAX_FORKS;
  329.       srandom((int) (getpid() * time((long *) 0)));
  330. ***************
  331. *** 375,380 ****
  332. --- 344,350 ----
  333.       if (!(random() % (1 + (40 - branch_freq))))
  334.           random_vines(xstart, ystart);
  335.       }
  336. +     XFlush(dpy);
  337.       exit(0);
  338.   }
  339.   
  340. ***************
  341. *** 422,428 ****
  342.   
  343.   do_leaf(x,y)
  344.   {
  345. !     int reverse_it;
  346.       if (interleaf && (reverse_it = !(random() % interleaf)))
  347.       reverse = !reverse;
  348.       /* start at x,y and rotate */
  349. --- 392,398 ----
  350.   
  351.   do_leaf(x,y)
  352.   {
  353. !     int reverse_it = 0;
  354.       if (interleaf && (reverse_it = !(random() % interleaf)))
  355.       reverse = !reverse;
  356.       /* start at x,y and rotate */
  357. ***************
  358. *** 439,446 ****
  359.   long mirror;
  360.   {
  361.       static col;
  362. !     int tmp, ox = x, oy = y, nx, ny, npts[1];
  363. !     struct pr_pos leaf2[sizeof(leaf) / sizeof(struct pr_pos)];
  364.   
  365.       /* magnify, move leaf into position, and mirror, if necessary */
  366.       for(tmp = 0; tmp < leafsize; tmp++) {
  367. --- 409,419 ----
  368.   long mirror;
  369.   {
  370.       static col;
  371. !     int tmp, ox = x, oy = y, nx, ny;
  372. ! #ifndef X11
  373. !     int npts[1];
  374. ! #endif
  375. !     point_t leaf2[sizeof(leaf) / sizeof(point_t)];
  376.   
  377.       /* magnify, move leaf into position, and mirror, if necessary */
  378.       for(tmp = 0; tmp < leafsize; tmp++) {
  379. ***************
  380. *** 463,469 ****
  381.       reverse = !reverse;
  382.   #ifdef X11
  383.       XFillPolygon(dpy, win, gc, leaf2, 28, Nonconvex, CoordModeOrigin);
  384. -     XFlush(dpy);
  385.   #else /* X11 */
  386.       npts[0] = 28;   /* kludge for middle line of leaf! */
  387.       pr_polygon_2(screen, 0, 0, 1, npts, leaf2, RAS_OP, (Pixrect *) 0,0,0);
  388. --- 436,441 ----
  389. ***************
  390. *** 500,506 ****
  391.   
  392.   /* foreach pt in object, rotate_pt() */
  393.   rotate_obj(object, newobject, npts, rotation)
  394. ! struct pr_pos object[], newobject[];
  395.   double rotation;
  396.   {
  397.       int i;
  398. --- 472,478 ----
  399.   
  400.   /* foreach pt in object, rotate_pt() */
  401.   rotate_obj(object, newobject, npts, rotation)
  402. ! point_t object[], newobject[];
  403.   double rotation;
  404.   {
  405.       int i;
  406. ***************
  407. *** 510,516 ****
  408.   
  409.   /* matrix multiplication */
  410.   rotate_pt(oldpt,newpt,rot)
  411. ! struct pr_pos *oldpt, *newpt;
  412.   double rot;
  413.   {
  414.       /* temp storage -- might want to copy to itself */
  415. --- 482,488 ----
  416.   
  417.   /* matrix multiplication */
  418.   rotate_pt(oldpt,newpt,rot)
  419. ! point_t *oldpt, *newpt;
  420.   double rot;
  421.   {
  422.       /* temp storage -- might want to copy to itself */
  423. ***************
  424. *** 592,605 ****
  425.           leaf_file = optarg;
  426.           when 'S':
  427.           stem_file = optarg;
  428. -         when 'F':
  429. -         do_fork = 1;
  430.           when '?':
  431.           errors = 1;
  432.       }
  433.   
  434.       if (errors) {
  435. !     fprintf(stderr, err_msg[0], argv[0]);
  436.           for (c = 1; err_msg[c]; c++)
  437.           fprintf(stderr, "%s\n", err_msg[c]);
  438.       exit(1);
  439. --- 564,575 ----
  440.           leaf_file = optarg;
  441.           when 'S':
  442.           stem_file = optarg;
  443.           when '?':
  444.           errors = 1;
  445.       }
  446.   
  447.       if (errors) {
  448. !     fprintf(stderr, err_msg[0], prog_name);
  449.           for (c = 1; err_msg[c]; c++)
  450.           fprintf(stderr, "%s\n", err_msg[c]);
  451.       exit(1);
  452. ***************
  453. *** 608,619 ****
  454.   
  455.   #ifdef X11
  456.   get_windows(){}
  457.   initialize_color()
  458.   {
  459. -     u_char red[256], green[256], blue[256];
  460. -     XColor color;
  461.       Colormap cm = DefaultColormapOfScreen(screen);
  462.   
  463.       color.flags = DoRed | DoGreen | DoBlue;
  464.       for (max_color = 0; max_color < 256; max_color++) {
  465.       if (season) {
  466. --- 578,617 ----
  467.   
  468.   #ifdef X11
  469.   get_windows(){}
  470. + /*
  471. +  * Open the display (connection to the X server).  If it's already
  472. +  * open, close it and reopen it since this is a child process and
  473. +  * each child needs its own connection.
  474. +  */
  475. + init_display()
  476. + {
  477. +     int x_error(), first_time = !dpy;
  478. +     char *getenv(), *p = getenv("DISPLAY");
  479. +     if (dpy)
  480. +     XCloseDisplay(dpy);
  481. +     if (!(dpy = XOpenDisplay(device? device : p? p : ""))) {
  482. +     fprintf(stderr, "%s: unable to open display '%s'\n",
  483. +         prog_name, XDisplayName(p));
  484. +     exit(1);
  485. +     }
  486. +     XSetErrorHandler(x_error);
  487. +     screen = ScreenOfDisplay(dpy, DefaultScreen(dpy));
  488. +     win = RootWindowOfScreen(screen);
  489. +     gc = XCreateGC(dpy, win, 0L, NULL);
  490. +     if (first_time)
  491. +     initialize_color();
  492. +     XFlush(dpy);
  493. + }
  494. + XColor color;
  495.   initialize_color()
  496.   {
  497.       Colormap cm = DefaultColormapOfScreen(screen);
  498.   
  499. +     if (!is_color)
  500. +     return;
  501.       color.flags = DoRed | DoGreen | DoBlue;
  502.       for (max_color = 0; max_color < 256; max_color++) {
  503.       if (season) {
  504. ***************
  505. *** 624,638 ****
  506.           color.green = (255 - max_color/3)<<8;
  507.       }
  508.       color.blue = (max_color/5)<<8;
  509.       if (!XAllocColor(dpy, cm, &color)) {
  510.           printf("ran out of colors at index %d\n", max_color--);
  511.           break;
  512.       }
  513.       colors[max_color] = color.pixel;
  514.       }
  515.   }
  516.   
  517. ! void
  518.   x_error(display, error)
  519.   Display    *display;
  520.   XErrorEvent    *error;
  521. --- 622,640 ----
  522.           color.green = (255 - max_color/3)<<8;
  523.       }
  524.       color.blue = (max_color/5)<<8;
  525. +     if (dbug)
  526. +         printf("%d=", max_color);
  527.       if (!XAllocColor(dpy, cm, &color)) {
  528.           printf("ran out of colors at index %d\n", max_color--);
  529.           break;
  530.       }
  531.       colors[max_color] = color.pixel;
  532. +     if (dbug)
  533. +         printf("%d, ", color.pixel);
  534.       }
  535.   }
  536.   
  537. ! int
  538.   x_error(display, error)
  539.   Display    *display;
  540.   XErrorEvent    *error;
  541. ***************
  542. *** 651,661 ****
  543.       XGetErrorDatabaseText(display, "XRequest", num, num, buffer, BUFSIZ);
  544.       fprintf(stderr, " %s\n", buffer);
  545.   
  546.       /* abort to core dump or global debug flag set.. */
  547. !     abort(0);
  548.   }
  549.   
  550.   #else /* X11 */
  551.   get_windows()
  552.   {
  553.       char name[WIN_NAMESIZE];
  554. --- 653,685 ----
  555.       XGetErrorDatabaseText(display, "XRequest", num, num, buffer, BUFSIZ);
  556.       fprintf(stderr, " %s\n", buffer);
  557.   
  558. +     printf("color.red = %d, green = %d, blue = %d, pixel = %d\n",
  559. +     color.red>>8, color.green>>8, color.blue>>8, color.pixel);
  560.       /* abort to core dump or global debug flag set.. */
  561. !     /* abort(0); */
  562. !     exit(0);
  563.   }
  564.   
  565.   #else /* X11 */
  566. + init_display()
  567. + {
  568. +     char groups[PIXPG_OVERLAY+1];
  569. +     if (screen)
  570. +     return;
  571. +     if (!(screen = pr_open(device)))
  572. +     exit(1); /* pr_open prints its own error messages (bad idea) */
  573. +     pr_available_plane_groups(screen, sizeof(groups), groups);
  574. +     if (groups[PIXPG_OVERLAY] && groups[PIXPG_OVERLAY_ENABLE] && !is_color) {
  575. +     pr_set_plane_group(screen, PIXPG_OVERLAY_ENABLE);
  576. +     pr_rop(screen, 0,0, WidthOfScreen(screen), HeightOfScreen(screen),
  577. +         PIX_SET, (Pixrect *) 0,0,0);
  578. +     pr_set_plane_group(screen, PIXPG_OVERLAY);
  579. +     }
  580. + }
  581.   get_windows()
  582.   {
  583.       char name[WIN_NAMESIZE];
  584. dan
  585. -----------------------------------------------------------
  586.             O'Reilly && Associates
  587.         argv@sun.com / argv@ora.com
  588.        632 Petaluma Ave, Sebastopol, CA 95472 
  589.      800-338-NUTS, in CA: 800-533-NUTS, FAX 707-829-0104
  590.     Opinions expressed reflect those of the author only.
  591.